package com.zbmsg.utils.common;

import java.util.HashMap;

import org.apache.commons.lang3.StringUtils;

import com.zbmsg.utils.json.JsonUtils;

public class Request {
	private long time;
	private int type;// 当前操作 1登入、2登出、3加入房间、4登出房间、5发送消息、6消息接收、7系统通知 对应枚举 MessageType

	private Object obj = new HashMap<Object, Object>();

	public Object getObj() {
		return obj;
	}

	public void setObj(Object obj) {
		this.obj = obj;
	}

	public long getTime() {
		return time;
	}

	public void setTime(long time) {
		this.time = time;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public static Request toRequest(String json) {
		if (!StringUtils.isEmpty(json)) {
			return JsonUtils.toBean(json, Request.class);
		}
		return null;
	}

	public <T> T toObject(Class<T> cls) throws Exception {
		return JsonUtils.toBean(JsonUtils.toJson(this.obj), cls);
	}

}
